var app = getApp()

Page({

  //数据
  data:{
      userInfo: {},
      left: "http://oky0avxwu.bkt.clouddn.com/left.png",
      right: "http://oky0avxwu.bkt.clouddn.com/right.png",
      title:"您已加入小胖，现在可以开始聊天了。",
      wenhou: "小胖是格悦科技的美食AI对话机器人，您可以和我聊天或输入午饭吃啥回答小胖的问题哦。",
      tishi: "“输入午饭吃啥可以进入问答模式”或“随便和小胖聊天哦”",
      msg: "",
      leftTalk: [
            {
                xiaopang: "小胖是格悦科技的美食AI对话机器人，您可以和我聊天或输入午饭吃啥回答小胖的问题哦。",
            },
            {
                xiaopang: "“输入午饭吃啥可以进入问答模式”或“随便和小胖聊天哦”",
            },
        ],
          leftXiao: [
            {
                show:0,
                xiaopang: "午饭吃啥！",
            },
        ],
      message: [],
      tip: '',
  },

  //用户对话函数
  bindKeyInput:function(e){
        this.setData({
            msg:e.detail.value,
        });
       console.log('37',this.data.msg)
  },

  //用户对话填充
  send:function(e) {
      var talk = this.data.msg;
      console.log('43',talk);
      var that = this;
      wx.request({
        url: 'https://xiaopang.demo.yanxishe.cc/h5/tuling/index?id=123&nickname=%E5%BC%A0%E4%B8%89&content=12',
        data: {"id":203020,"content":talk,"nickname":"io","sex":"男"},
        method: 'GET', 
        header: {"Content-Type":"json"},
        success: function(res){
            var obj = res.data.tip;
            console.log(obj);

            that.setData({
　　　　　       tip:obj
　　　　　　　});

            var message = that.data.message;
            var talkmsg = {msg:talk,xiaopang:""};
            console.log("4",that.data.tip);
            talkmsg.xiaopang = that.data.tip;
            if(talk.length < 1){
                return;
            } else {
                message.push(talkmsg);
                that.setData({
                    message: message,
                    msg: '',
                });
            }
        },
        fail: function() {
          console.log("小胖不在家！")
        },
        complete: function() {
          console.log("快来和小胖聊天吧！")
        }
      });
  },

  //页面渲染完成后动作
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
      console.log(userInfo);
    })
  }
})